const koa = require('koa');
const static = require('koa-static');
const cors = require('koa2-cors');
const Router = require('koa-router');
const ali = require('./aliPay'); //SDK('收落款'，’订单id‘， ’总金额‘)
const router = new Router();
/*router.get('regisster', async function (ctx) {
    let {username,pwd} = ctx.request.query
    console.log(ctx.query)
    if (!username) {
        ctx.body = {
            code: 1000,
            data: []
        }
    } else if (!pwd) {
        ctx.body = {
            code: 1001,
            data: []
        }
    } else {
        ctx.body = {
            code: 1002,
            data: {
                uid: '成功'
            }
        }
    }
})*/
router.get('/alipay', async function (ctx) {
    let { price } = ctx.request.query;
    if(price){
        ctx.body = `https://openapi.alipaydev.com/gateway.do?${ali('18103收款', ~~(Math.random()*999999999) + '', price)}`;
    }else{
ctx.body = '请输入价格';
    }
});
router.post('/paySuccess', async(ctx, next)=>{
    let {out_trade_no} = ctx.request.body;
    console.log(out_trade_no);
    ctx.body = 'success';
    await next();
});
const app = new koa();
// 允许任何原
app.use(cors({
    origin: '*'
}));
app.use(static('./dist'));
app.use(router.routes());
app.listen(9999, function () {
    console.log('服务器已运行在本地端口 9999')
});
